package start.demo01.fileIO;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Task04 {
    public static void main(String[] args) throws IOException {
        String path="D:/iotest2";
        String name="Stream.txt";
        File dir=new File(path);
        File file =new File(dir,name);
        dir.mkdir();
        file.createNewFile();
        System.out.println(file.length()+"B");
        try(FileWriter writer=new FileWriter(file);
            FileReader read=new FileReader(file);){
            writer.write("I love you!");
            writer.close();//此处不关闭，将无法读到字符,可能读到空格，这与字节流不同
            int val=-1;
            while((val=read.read())!=-1){//每次仅能读到一个字符
                System.out.print((char)val);
            }
        }catch(IOException e){
            e.printStackTrace();
        }
    }

}
